import axios from "axios"

const instance = axios.create({
    baseURL: "http://kumanxuan1.f3322.net:8881/cms",
    timeout: 5000
})

instance.interceptors.request.use(config => {
    if (config.url === "/sendSMS" || config.url === "/wechatUsers/PCLogin") {
        config.headers["Content-Type"] = "application/x-www-form-urlencoded";
    }
    return config
}, err => {
    return Promise.reject(err)
})

instance.interceptors.response.use(function (response) {
    if (response.data.code != 0 && response.data.code != 400 && response.data.code != 407) {
        alert(response.data.msg)
        return false
    }
    return response.data
}), err => {
    return Promise.reject(err)
}

export default instance